<script lang="ts" setup>
// import { useMainStore } from '@/store/main'
import { onMounted, ref } from 'vue'
import { MoreFilled } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import Chart from '@/components/charts/index.vue'
import dayjs from 'dayjs'
import daglService from '@/api/dagl'
import { useRouter } from 'vue-router'
import Calendar from 'mpvue-calendar'

const router = useRouter()

onMounted(() => {
  let a = [dayjs(new Date()).format('YYYY-M-D')]
  for (let index = 0; index < a.length; index++) {
    remarks.value[a[index]] = '今日'
  }
  selectDay(dayjs(new Date()).format('YYYY-M-DD'))
  // 获取归档情况统计 档案统计-归档情况统计
  getQueryGdqktj()
  // 查询年度归档案件归档趋势
  getQueryNdgdsjtj()
})

// 归档情况统计 档案统计-归档情况统计
const charData = ref()

const getQueryGdqktj = () => {
  const params = {
    tjlx: tjlx.value,
  }
  daglService
    .queryGdqktj(params)
    .then((res) => {
      // 操作成功后
      charData.value = res.data
    })
    .catch((err) => {
      !err.isError && ElMessage({ type: 'warning', message: err.message })
    })
}

const tjlxChange = (val: any) => {
  tjlx.value = val
  getQueryGdqktj()
}

const ndgdsjtjData = ref()
// 查询年度归档案件归档趋势
const getQueryNdgdsjtj = () => {
  const params = {}
  daglService
    .queryNdgdsjtj(params)
    .then((res) => {
      // 操作成功后
      ndgdsjtjData.value = res.data
    })
    .catch((err) => {
      !err.isError && ElMessage({ type: 'warning', message: err.message })
    })
}

const weeks = ['一', '二', '三', '四', '五', '六', '日']
const remarks: any = ref({}) //仅展示今日
const tileContent = ref({})
const selectDate = ref(dayjs(new Date()).format('YYYY-M-DD'))
const selectDay = (val: any) => {
  //
  console.log(val)
}
const activities = [
  {
    content: [
      {
        nr: '【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！',
      },
      {
        nr: '【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！',
      },
      {
        nr: '【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！',
      },
    ],

    timestamp: '归档预警',
    size: 'large',
    icon: MoreFilled,
  },
  {
    content: [
      {
        nr: '【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！',
      },
      {
        nr: '【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！',
      },
      {
        nr: '【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！',
      },
    ],
    timestamp: '归档预警',
  },
  {
    content: [
      {
        nr: '【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！',
      },
      {
        nr: '【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！',
      },
      {
        nr: '【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！【褚庆华、张三丰盗窃案】已办结，还未完成归档流程，今日将超期，请及时处理！',
      },
    ],
    timestamp: '归档预警',
  },
]
const kjrkList = ref([
  {
    rkmc: '案件归档',
    icon: 'icon-ajgd',
    router: '/ajgd',
  },
  {
    rkmc: '检察官审核',
    icon: 'icon-gdyj',
    router: '/jcgsh',
  },
  {
    rkmc: '档案初验',
    icon: 'icon-ajgd2',
    router: '/dacy',
  },
  {
    rkmc: '档案复验',
    icon: 'icon-gdyj2',
    router: '/dafy',
  },
  {
    rkmc: '档案管理',
    icon: 'icon-ajgd3',
    router: '/dagl',
  },
  {
    rkmc: '退改审批',
    icon: 'icon-gdyj3',
    router: '/tgsh',
  },
])
const getIconUrl = (imgUrl: any) => {
  try {
    //存在则加载图片
    return new URL(`../../assets/images/home/${imgUrl}.png`, import.meta.url).href
  } catch (e) {
    //不存在则catch中返回默认的图片
    return new URL(`../../assets/images/home/icon-ajgd.png`, import.meta.url).href
  }
}
const tjlx = ref('1')

const kjrkDetailHandler = (obj: any) => {
  router.push(obj.router)
}

// 入参写法
// const props = defineProps({})
// emit抛出事件
// const emit = defineEmits([])
// const mainStore = useMainStore()
// const clickdemo = () => {
//   mainStore.setDemo('测试测试')
// }

// solts和attrs
// const slots = useSlots()
// const attrs = useAttrs()

// 自定义指令
// const vMyDirective = {
//   beforeMount: () => {
//     // 操作
//   },
// }

// 抛出方法或变量给外部ref调用
// defineExpose({})

// 日期时间转换插件dayjs
// const time = ref(dayjs().format('YYYY年MM月DD日 HH:mm:ss'))
</script>
<template>
  <div class="home-index">
    <div class="index-content">
      <div class="dbsx home-content">
        <div class="tit-div">
          <img src="@/assets/images/home/icon-tz.png" alt="" class="tit-img" /> 待办事项
        </div>
        <div class="content-div dbsx-div">
          <div class="dbsx-content">
            <div class="dbsx-yh-div">
              <img src="@/assets/images/yh.png" alt="" class="dbsx-tx" />
            </div>
            <div class="dbsx-yhxx">
              <span class="user-sapn"> hi，用户 </span>
              <span class="user-xx">欢迎您来到门户</span>
            </div>
            <div class="dbsx-all">
              <div class="dbsx-xx-div">
                <div class="border-div"></div>
                <div class="zt-div">未提交</div>
                <div class="count-div">3</div>
              </div>
              <div class="dbsx-xx-div ytj">
                <div class="border-div"></div>
                <div class="zt-div">已提交</div>
                <div class="count-div">3</div>
              </div>
              <div class="dbsx-xx-div yth">
                <div class="border-div"></div>
                <div class="zt-div">已退回</div>
                <div class="count-div">3</div>
              </div>
              <div class="dbsx-xx-div tgz">
                <div class="border-div"></div>
                <div class="zt-div">退改中</div>
                <div class="count-div">3</div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="gdyj home-content">
        <div class="tit-div">
          <img src="@/assets/images/home/icon-tz.png" alt="" class="tit-img" /> 归档预警
        </div>
        <div class="content-div">
          <div class="calendar-div">
            <Calendar
              ref="smallCalendar"
              :language="'cn'"
              style="width: 100% !important"
              :select-date="selectDate"
              completion
              backgroundText
              selectMode="select"
              :weeks="weeks"
              :remarks="remarks"
              :tileContent="tileContent"
              @onSelect="selectDay"
            />
          </div>
          <div class="tieme-line">
            <el-timeline class="el-time">
              <el-timeline-item
                v-for="(activity, index) in activities"
                :key="index"
                :icon="activity.icon"
                :size="activity.size"
                :timestamp="activity.timestamp"
                :hide-timestamp="true"
                :hollow="true"
                placement="top"
              >
                <div class="timestamp">
                  {{ activity.timestamp }}
                </div>
                <div class="time-div" v-for="(item, i) in activity.content" :key="i">
                  <span class="time-nr" :title="item.nr"> {{ item.nr }}</span>
                </div>
              </el-timeline-item>
            </el-timeline>
          </div>
        </div>
      </div>
    </div>
    <div class="index-content">
      <div class="tj-div home-content">
        <div class="tit-div">
          <img src="@/assets/images/home/icon-gdqktj.png" alt="" class="tit-img" /> 归档情况统计
        </div>
        <div class="content-div chart-div">
          <div class="chart-query">
            <div class="gdl-div">
              <el-progress
                :text-inside="true"
                :stroke-width="26"
                color="#a6d1ff"
                :percentage="(charData?.gdl * 100).toFixed(2)"
              />
            </div>
            <div class="rido-div">
              <el-radio-group v-model="tjlx" size="large" @change="tjlxChange">
                <el-radio-button label="年" value="1" />
                <el-radio-button label="月" value="2" />
                <el-radio-button label="日" value="3" />
              </el-radio-group>
            </div>
          </div>

          <Chart chartType="homeBar" :chartData="charData"></Chart>
        </div>
      </div>
      <div class="tj-div home-content">
        <div class="tit-div">
          <img src="@/assets/images/home/icon-ajgdqs.png" alt="" class="tit-img" /> 案件归档趋势
        </div>
        <div class="content-div chart-div">
          <Chart chartType="line" :chartData="ndgdsjtjData"></Chart>
        </div>
      </div>
      <div class="kjrk-all home-content">
        <div class="tit-div">
          <img src="@/assets/images/home/icon-kjrk.png" alt="" class="tit-img" /> 快捷入口
        </div>
        <div class="content-div kjrk-content">
          <div
            class="krjk-div"
            v-for="(item, index) in kjrkList"
            :key="index"
            @click="kjrkDetailHandler(item)"
          >
            <img :src="getIconUrl(item.icon)" alt="" class="kjrk-img" />
            <!-- <img src="@/assets/images/home/icon-ajgd.png" alt="" class="kjrk-img" /> -->
            <span class="kjrk-span">{{ item.rkmc }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.home-index {
  width: 100%;
  height: 100% !important;
  overflow: auto;
  display: flex;
  flex-direction: column;
  .index-content {
    flex: 1;
    display: flex;
    &:last-child {
      margin-top: 16px;
    }
  }
  .dbsx {
    width: 400px;
    margin-right: 16px;
  }
  .gdyj {
    flex: 1;
    height: 100%;
    width: calc(100% - 410px);
  }
  .home-content {
    display: flex;
    flex-direction: column;
    border-radius: 5px;
    height: 100%;
    .tit-div {
      height: 40px;
      width: 100%;
      line-height: 40px;
      display: flex;
      align-items: center;
      background-color: #d4e6f4;
      border-radius: 5px 5px 0px 0px;
      font-family: MicrosoftYaHei;
      font-size: 16px;
      font-weight: normal;
      font-stretch: normal;
      color: #006295;
      padding: 0px 15px;
      .tit-img {
        margin-right: 5px;
      }
    }
    .content-div {
      flex: 1;
      background-color: #fff;
      border-radius: 0px 0px 5px 5px;
      display: flex;
      height: calc(100% - 40px);
    }
    .dbsx-div {
      justify-content: center;
      align-items: flex-end;
      padding: 15px;
      min-height: 400px;
      max-height: 400px;
    }
    .dbsx-content {
      width: 360px;
      height: calc(100% - 35px);
      min-height: 300px;
      background: url('@/assets/images/home/dbsx-bg.png') no-repeat;
      background-size: 100%;
      position: relative;
      padding: 16px;
      display: flex;
      justify-content: center;
      flex-direction: column;
      .dbsx-yh-div {
        width: 90px;
        height: 90px;
        position: absolute;
        left: calc(50% - 45px);
        top: -45px;
        background-color: #fff;
        border-radius: 45px;
        display: flex;
        align-items: center;
        justify-content: center;
        .dbsx-tx {
          width: 80px;
          height: 80px;
        }
      }
      .dbsx-yhxx {
        // height: 40px;
        display: flex;
        text-align: center;
        flex-direction: column;
        margin-top: 40px;
        .user-sapn {
          font-size: 20px;
          font-weight: bold;
          font-stretch: bold;
          line-height: 27px;
          color: #006295;
        }
        .user-xx {
          font-family: MicrosoftYaHei;
          font-size: 14px;
          font-weight: normal;
          color: #006295;
        }
      }
      .dbsx-all {
        flex: 1;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: flex-end;
      }
      .dbsx-xx-div {
        width: 155px;
        height: 80px;
        background-color: #ffffff;
        border-radius: 10px;
        align-items: center;
        padding: 20px;
        display: flex;
        .border-div {
          width: 2px;
          height: 42px;
          background-color: #006295;
        }
        .zt-div {
          font-family: MicrosoftYaHei;
          font-size: 16px;
          font-weight: normal;
          font-stretch: normal;
          color: #4f5e7b;
          margin-left: 10px;
        }
        .count-div {
          font-family: DINMittelschriftLTW1G;
          font-size: 24px;
          font-weight: normal;
          font-stretch: normal;
          color: #3e90bd;
          flex: 1;
          text-align: right;
        }
      }
      .ytj {
        .border-div {
          background-color: #0cbdb3;
        }
        .count-div {
          color: #0cbdb3;
        }
      }
      .yth {
        .border-div {
          background-color: #ff6363;
        }
        .count-div {
          color: #ff6363;
        }
      }
      .tgz {
        .border-div {
          background-color: #00c0ff;
        }
        .count-div {
          color: #00c0ff;
        }
      }
    }
    .calendar-div {
      width: 325px;
      height: 329px;
    }
    .tieme-line {
      flex: 1;
      padding: 30px 20px 30px 30px;
      max-height: 400px;
      overflow: auto;
      .el-time {
        padding-left: 2px;
        height: 100%;
        width: 100%;
        overflow: auto;
        // 滚动条
        &::-webkit-scrollbar {
          display: none;
        }
      }
      .timestamp {
        text-align: left;
        margin-bottom: 8px;
        font-size: 16px;
        font-weight: bold;
        font-stretch: bold;
        color: #2d405e;
      }
      .time-div {
        font-family: MicrosoftYaHei;
        font-size: 14px;
        font-weight: normal;
        font-stretch: normal;
        color: #526a89;
        width: 100%;
        position: relative;
        display: flex;
        align-items: center;
        margin: 15px 0px;
        &::before {
          content: '';
          width: 5px !important;
          height: 5px !important;
          background-color: #7f92bf;
          border-radius: 5px;
          position: absolute;
        }
        .time-nr {
          margin-left: 16px;
          flex: 1;
          white-space: nowrap; /* 确保文本在一行内显示 */
          overflow: hidden; /* 超出容器的文本将被隐藏 */
          text-overflow: ellipsis; /* 超出的文本显示为省略号 */
          width: 400px;
        }
      }
    }
  }
  .tj-div {
    flex: 1;
    margin-right: 16px;
    .chart-div {
      padding: 16px;
      flex-direction: column;
      #qjgdqs-chart {
        width: 100%;
        height: 100%;
      }
    }
  }
  .kjrk-all {
    width: 350px;
    .kjrk-content {
      display: flex;
      padding: 20px;
      flex-wrap: wrap;
      justify-content: space-between;
      overflow: auto;
      .krjk-div {
        width: 145px;
        height: 84px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 16px;
        cursor: pointer;
        &:hover {
          background-color: #f1f6ff;
          border: solid 1px #d0deeb;
        }
        .kjrk-img {
          width: 45px;
          height: 45px;
        }
        .kjrk-span {
          font-family: MicrosoftYaHei;
          font-size: 16px;
          color: #4f5e7b;
          margin-left: 10px;
        }
      }
    }
  }
  .chart-query {
    height: 30px;
    width: 100%;
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    justify-content: space-between;
    .gdl-div {
      flex: 1;
      height: 30px;
      // background-color: #f0f5ff;
    }
    .rido-div {
      margin-left: 20px;
      :deep().el-radio-button__inner {
        padding: 0px;
        width: 32px;
        height: 24px;
        line-height: 24px;
        color: #095c9e;
        border-color: #5baae7;
      }
      :deep().el-radio-button__original-radio:checked + .el-radio-button__inner {
        color: #fff;
        background-color: #5baae7;
      }
    }
  }
}
</style>
